/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.gwt.basics.service;

import com.genia.toolbox.web.gwt.basics.bean.FileInformation;
import com.genia.toolbox.web.gwt.basics.client.bean.GwtFileInformation;
import com.genia.toolbox.web.gwt.basics.client.service.GwtFileUploadService;
import com.genia.toolbox.web.gwt.basics.manager.GwtFileUploadManager;

/**
 * implementation of {@link GwtFileUploadService}.
 */
public class GwtFileUploadServiceImpl
    implements GwtFileUploadService
{

  /**
   * the {@link GwtFileUploadManager} to use.
   */
  private GwtFileUploadManager gwtFileUploadManager;



  /**
   * return a new identifier to be used in the client-server communication.
   * 
   * @return a new identifier to be used in the client-server communication
   * @see com.genia.toolbox.web.gwt.form.client.service.FormService#getNewIdentifier()
   */
  public Long getNewIdentifier()
  {
    return getGwtFileUploadManager().getNewIdentifier();
  }



  /**
   * get the progress of the upload of a file.
   * 
   * @param id
   *          the identifier of the file to monitor.
   * @return the progress of upload of the file (a number between 0 and 100) *
   * @see com.genia.toolbox.web.gwt.form.client.service.FormService#getUploadProgress(java.lang.Long)
   */
  public Integer getUploadProgress(Long id)
  {
    Integer uploadProgress = getGwtFileUploadManager().getUploadProgress(id);
    return uploadProgress;
  }



  /**
   * retrieve the informations about an uploaded file.
   * 
   * @param identifier
   *          the session identifier of the uploader file.
   * @return the informations about an uploaded file
   * @see com.genia.toolbox.web.gwt.form.client.service.FormService#getFileInformation(java.lang.Long)
   */
  public GwtFileInformation getFileInformation(Long identifier)
  {
    if (identifier == null) {
      return null;
    }
    FileInformation fileInformation = getGwtFileUploadManager().getFileInformation(identifier);
    if (fileInformation == null) {
      return null;
    }
    return fileInformation.getGwtFileInformation();
  }



  /**
   * getter for the gwtFileUploadManager property.
   * 
   * @return the gwtFileUploadManager
   */
  public GwtFileUploadManager getGwtFileUploadManager()
  {
    return gwtFileUploadManager;
  }



  /**
   * setter for the gwtFileUploadManager property.
   * 
   * @param gwtFileUploadManager
   *          the gwtFileUploadManager to set
   */
  public void setGwtFileUploadManager(GwtFileUploadManager gwtFileUploadManager)
  {
    this.gwtFileUploadManager = gwtFileUploadManager;
  }

}
